class_name Small extends Node2D

var scale_inPoint = Vector2(0.18,0.18)			# 在point上时，缩放比例
var player:Player
var point:Point
var level:int = 1
var energy:int = 0		#能量
var is_ready:bool = false

func _ready():
	$"放大版".scale = Vector2(0,0)

func init(playerr:Player,pointt:Point):
	player = playerr
	point = pointt
	position = pointt.position
	$"放大版/外框".self_modulate = player.color
	$"缩小版/Sprite2D".self_modulate = player.color
	point.small = self
	point.changeColor(player.color)
	$"缩小版".scale = scale_inPoint
	visible = false
	$"缩小版/可行动提示点".visible = is_ready
	$"放大版/可行动提示点".visible = is_ready
	await get_tree().create_timer(4).timeout
	visible = true

func on_mouse_entered():
	$"缩小版/缩小版动画".play("鼠标进入")
	
func on_mouse_exited():
	$"缩小版/缩小版动画".play("鼠标移出")
	
func click():
	$"放大版/放大版动画".play("点击放大")
	
func detailHide():
	$"放大版/放大版动画".play("缩小隐藏")
	
func _on_animation_started(anim_name):
	if anim_name == "点击放大":
		ObjectManager.gameManager.layer_chesses.remove_child(self)
		ObjectManager.gameManager.layer_display.add_child(self)

func _on_animation_finished(anim_name):
	if anim_name == "缩小隐藏":
		ObjectManager.gameManager.layer_display.remove_child(self)
		ObjectManager.gameManager.layer_chesses.add_child(self)

# 行动冷却、状态更新、等级、能量、科技点
func update(data:Dictionary):
	energy = data.energy
	if ObjectManager.gameManager.me_player == null || player.is_me:
		ObjectManager.gameManager.ui.updateSwordOrder(energy)
	if is_ready != data.is_ready:
		if player.is_me:
			is_ready = data.is_ready
			$"缩小版/可行动提示点".visible = is_ready
			$"放大版/可行动提示点".visible = is_ready

func die():
	if player.is_me:
		ObjectManager.toast.showToast("可以继续观战")
	else:
		ObjectManager.toast.showToast("玩家死亡: "+player.username)
	player.alive = false
	queue_free()
